import router from '../router'
import store from '../store'
import {setBackUrl} from "./auth";
const whiteList = ['/login']
import * as types from '../store/types'
router.beforeEach((to,from,next) => {
    //记录当前地址
    console.log("========")
    store.commit(types.SET_CURRENT_URL,to.fullPath)
    let loginToken = store.getters.loginToken
    if(loginToken||whiteList.indexOf(to.path)>-1){//登录状态 或者白名单 直接放行
        //ios的话 记录首次进入的地址
        if (!store.getters.firstUrl) { //
            store.commit(types.SET_FIRST_URL,document.URL)
        }
        next()
    }else { //记录当前页面 跳转到登录
        setBackUrl(to.fullPath)
        //跳转到登录页面
        router.push({
            path:'/login'
        })
    }

})


